package com.test.textGame.mq;

import com.alibaba.fastjson.JSONObject;
import com.test.textGame.algorithm.TopK;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
//import org.springframework.amqp.support.Correlation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RabbitSlaverProducer {
    @Value("${top10.sort.group1.exchange}")
    private String exchangeName;
    @Value("${top10.sort.group1.routekey}")
    private String routeKey;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendPlayerScore(TopK.Node node) {
        String msg = JSONObject.toJSONString(node);
        log.info("top10从节点发送消息："+msg);

        rabbitTemplate.convertAndSend(exchangeName, routeKey, JSONObject.toJSONString(msg), message -> {
            message.getMessageProperties().setDeliveryMode(MessageDeliveryMode.PERSISTENT);

            return message;
        });
    }
}
